package me.zhengjie.config.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import me.zhengjie.config.enums.QrCodeTypeEnum;
import me.zhengjie.utils.StringUtils;

import java.io.File;

public class QrCodeUtils {

    private QrCodeUtils(){}
    private static class QrCodeUtilsHolder {
        private static final QrCodeUtils INSTANCE = new QrCodeUtils();
    }

    public static final QrCodeUtils getInstance() {
        return QrCodeUtils.QrCodeUtilsHolder.INSTANCE;
    }

    public String generate(String content){
        return generate(content, UUID.fastUUID().toString(true),300, 300,"");
    }
    public String generate(String content, QrCodeTypeEnum qrCodeTypeEnum){
        return generate(content, qrCodeTypeEnum.getType()+"_"+UUID.fastUUID().toString(true),300, 300,"");
    }
    public String generate(String content,int width,int height){
        return generate(content, UUID.fastUUID().toString(true),width, height,"");
    }

    public String generate(String content,String picName){
        return generate(content, picName,300, 300,"");
    }

    public String generate(String content,String picName,String filePath){
        return generate(content, picName,300, 300,filePath);
    }

    public String generate(String content,String picName,int width,int height,String filePath){
        if (StringUtils.isBlank(filePath)){
            filePath = "/home/eladmin/file/"+picName+".jpg";
        }else {
            filePath = filePath + "/"+ picName+".jpg";
        }
        File generate = QrCodeUtil.generate(content, width, height, FileUtil.file(filePath));
        //File gerate = QrCodeUtil.generate(content, QrConfig.create().setImg(""), FileUtil.file(filePath));
        return generate.getAbsolutePath();
    }

}
